package com.xu.ai.mcp.syncserver.tools;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 日期时间工具
 *
 * @author xuguan
 * @since 2025/9/17
 */
@Service
public class DateTimeTool implements ITool {

    @Tool(description = "获取用户时区的当前日期和时间")
    public String getCurrentDateTime(@ToolParam(description = "日期时间格式", required = false) String pattern) {
        if (!StringUtils.hasText(pattern)) {
            pattern = "yyyy-MM-dd HH:mm:ss";
        }
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        final ZonedDateTime zonedDateTime = LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId());
        return formatter.format(zonedDateTime);
    }
}
